<template>
  <div class="about-container" :class="{ 'dark-theme': isDarkMode }">
    <div class="about-card">
      <h2 class="about-title">关于我们</h2>
      <div class="developers-section">
        <div class="team-member">
          <br>
          <ul class="member-list">
            <li 
              v-for="member in coreMembers" 
              :key="member.name" 
              class="member-item"
            >
              <span class="dev-name">{{ member.name }}</span>
              <div class="contribution-badge">{{ member.role }}</div>
            </li>
          </ul>
        </div>

        <div class="contributors-section">
          <h3 class="section-title">视频贡献体系</h3>
          <br>
          <div class="timeline">
            <div 
              v-for="contributor in groupedCourses" 
              :key="contributor.uploader"
              class="contributor"
            >
              <div class="contributor-header">
                <span class="contributor-name">{{ contributor.uploader }}</span>
                <span class="contributor-years">{{ contributor.yearRange }}</span>
              </div>
              <ul class="course-list">
                <li 
                  v-for="item in contributor.courses" 
                  :key="item.title" 
                  class="course-item"
                >
                  <span class="course-year">{{ item.year }}</span>
                  <div class="course-content">
                    <div class="course-title">{{ item.title }}</div>
                    <div class="course-tags">
                      <span 
                        v-for="(tag, index) in item.tags" 
                        :key="index"
                        class="tag"
                      >
                        {{ tag }}
                      </span>
                    </div>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { computed, inject } from 'vue';
  // 由于uploader-config.yaml位于项目根目录，不在src目录下，保留相对路径
  import config from '@/config/uploader-config.yaml';
  
  // 注入深色模式状态
  const { isDarkMode } = inject('darkMode', { isDarkMode: false });

  // 从配置文件中获取课程信息
  const Coursesconfig = config.courses;
  // 从配置文件中获取核心成员信息
  const coreMembers = config.coreMembers;
  // 动态计算课程分组
  const groupedCourses = computed(() => {
    const groups = Coursesconfig.reduce((acc, course) => {
      const uploader = course.uploader;
      if (!acc[uploader]) {
        acc[uploader] = {
          uploader,
          courses: [],
          years: new Set()
        };
      }
      acc[uploader].courses.push(course);
      acc[uploader].years.add(course.year);
      return acc;
    }, {});

    return Object.values(groups).map(group => ({
      ...group,
      yearRange: getYearRange([...group.years])
    }));
  });

  // 计算年份范围
  const getYearRange = (years) => {
    const sorted = [...new Set(years)].sort();
    return sorted.length > 1 
      ? `${sorted[0]}-${sorted[sorted.length - 1]}`
      : `${sorted[0]}`;
  };
</script>


<style scoped>
.about-container {
  padding: 2rem;
  background: var(--bg-color);
  min-height: 100vh;
  transition: background-color 0.3s ease;
}

/* 深色主题特定样式 */
.dark-theme .contributor:before {
  border-color: var(--card-bg);
}

.about-card {
  max-width: 1200px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 8px 30px var(--card-shadow);
  padding: 2.5rem;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.about-title {
  font-size: 2.2rem;
  color: var(--text-color);
  margin-bottom: 2rem;
  position: relative;
  padding-left: 1rem;
}

.developers-section {
  display: grid;
  gap: 2.5rem;
}

.member-list {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
  list-style-type: none;
}

.member-item {
  position: relative;
  padding: 1.2rem 2rem;
  background: var(--card-bg);
  border-radius: 8px;
  transition: transform 0.2s, background-color 0.3s ease;
  border: 1px solid var(--border-color, #e0e0e0);
}

.member-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px var(--hover-shadow);
}

.dev-name {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-color);
}

.contribution-badge {
  font-size: 0.9rem;
  color: var(--text-color-secondary, #7f8c8d);
  margin-top: 0.5rem;
}

.timeline {
  position: relative;
  padding-left: 20px;
  border-left: 2px solid var(--border-color, #e0e0e0);
}

.contributor {
  margin-bottom: 2rem;
  padding-left: 2rem;
  position: relative;
}

.contributor:before {
  content: "";
  position: absolute;
  left: -8px;
  top: 5px;
  width: 14px;
  height: 14px;
  background: var(--icon-color, #3498db);
  border-radius: 50%;
  border: 3px solid var(--card-bg);
  box-shadow: 0 0 0 2px var(--icon-color, #3498db);
  transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
}

.course-list {
  margin-top: 1rem;
}

.course-item {
  display: flex;
  gap: 1.5rem;
  padding: 1.2rem;
  background: var(--card-bg);
  border-radius: 8px;
  margin-bottom: 1rem;
  transition: box-shadow 0.2s, background-color 0.3s ease;
  border: 1px solid var(--border-color, #e0e0e0);
}

.course-item:hover {
  box-shadow: 0 4px 12px var(--hover-shadow);
}

.course-year {
  font-weight: 600;
  color: var(--icon-color, #3498db);
  min-width: 60px;
  transition: color 0.3s ease;
}

.course-title {
  font-weight: 500;
  color: var(--text-color);
  margin-bottom: 0.5rem;
}

.course-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
  background: var(--icon-bg, rgba(52, 152, 219, 0.1));
  color: var(--icon-color, #3498db);
  border-radius: 20px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.contributor-name {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-color);
  position: relative;
  padding-left: 28px;
  letter-spacing: -0.5px;
  transition: color 0.3s ease;
}

.contributor-name:before {
  content: "👨💻";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  font-size: 1.1rem;
  opacity: 0.9;
}

.contributor-years {
  font-size: 0.95rem;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(135deg, var(--icon-color, #3498db) 0%, var(--text-color, #2c3e50) 100%);
  padding: 4px 12px;
  border-radius: 16px;
  margin-left: 12px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px var(--card-shadow);
}

.contributor-years:before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 25%,
    rgba(255, 255, 255, 0.2) 50%,
    transparent 75%
  );
  animation: shine 2s infinite;
  transition: background 0.3s ease;
}

/* 在深色模式下禁用闪光效果 */
.dark-theme .contributor-years:before {
  animation: none;
  background: transparent; /* 完全移除背景渐变 */
  opacity: 0; /* 确保元素完全不可见 */
}

@keyframes shine {
  100% {
    left: 200%;
  }
}

/* 悬停效果 */
.contributor:hover .contributor-name {
  color: var(--icon-color, #3498db);
  text-shadow: 0 2px 4px var(--card-shadow);
}

.contributor:hover .contributor-years {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--hover-shadow);
}

@media (max-width: 768px) {
  .about-card {
    padding: 1.5rem;
  }
  
  .member-list {
    flex-direction: column;
  }
  
  .course-item {
    flex-direction: column;
    gap: 0.8rem;
  }
  
  .course-year {
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed var(--border-color, #ddd);
  }
}

</style>
